﻿// http://pinvoke.net/default.aspx/shell32/ShellExecuteEx.html

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace NExplorer.Core.Commands
{
	internal class PropertiesCommand : AnyItemsCommandBase
	{
		#region SHELLEXECUTEINFO struct

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
		public struct SHELLEXECUTEINFO
		{
			public int cbSize;
			public uint fMask;
			public IntPtr hwnd;
			public String lpVerb;
			public String lpFile;
			public String lpParameters;
			public String lpDirectory;
			public int nShow;
			public int hInstApp;
			public int lpIDList;
			public String lpClass;
			public int hkeyClass;
			public uint dwHotKey;
			public int hIcon;
			public int hProcess;
		}

		#endregion

		#region consts

		private const int SW_SHOW = 5;
		private const uint SEE_MASK_INVOKEIDLIST = 12;

		#endregion

		[DllImport("shell32.dll", CharSet = CharSet.Auto)]
		static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

		public PropertiesCommand() 
			: base("Properties")
		{}

		protected override void Execute(FileSystemInfo fileSystemInfo)
		{
			SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
			info.cbSize = Marshal.SizeOf(info);
			info.lpVerb = "properties";
			info.lpFile = fileSystemInfo.FullName;
			info.nShow = SW_SHOW;
			info.fMask = SEE_MASK_INVOKEIDLIST;
			
			ShellExecuteEx(ref info);
		}
	}
}